//
//  SAAllocateDocumentsCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2022/4/20.
//

#import "SAAllocateDocumentsCell.h"
#import "SAAllocateDocumentsModel.h"

@interface SAAllocateDocumentsCell ()

@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UIImageView *imageV2;

@end

@implementation SAAllocateDocumentsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAAllocateDocumentsModel *)model {
    _model = model;
    self.titleLab.text = [NSString stringWithFormat:@"申请店：%@",model.storeName];
    self.contentLab.text = [NSString stringWithFormat:@"调出店：%@",model.targetStoreName];
    self.numLab.text = model.dispatchCount;
    NSString *price = [NSString stringWithFormat:@"%0.2lf",[model.dispatchTotalPrice doubleValue]/100];
    self.priceLab.text = [NSString stringWithFormat:@"￥:%@",price];
    NSString *imageName = [NSString stringWithFormat:@"AllocateStatus_%@",model.tradeStatus];
    self.imageV.image = [UIImage imageNamed:imageName];
    
    NSString *productViewCostPrice = [NSString stringWithFormat:@"%@",[SAValueManger shareInStance].userInfo.menuList[1][@"perms"][@"productViewCostPrice"]];
    if ([productViewCostPrice isEqualToString:@"1"]) {
        self.priceLab.text = @"￥:******";
    }
}

-(void)setDistributionModel:(SAAllocateDocumentsModel *)distributionModel {
    _distributionModel = distributionModel;
    
    self.titleLab.text = [NSString stringWithFormat:@"配出店：%@",distributionModel.storeName];
    self.contentLab.text = [NSString stringWithFormat:@"接收店：%@",distributionModel.targetStoreName];
    self.numLab.text = distributionModel.dispatchCount;
    NSString *price = [NSString stringWithFormat:@"%0.2lf",[distributionModel.dispatchTotalPrice doubleValue]/100];
    self.priceLab.text = [NSString stringWithFormat:@"￥:%@",price];
    
    NSString *imageName = [NSString stringWithFormat:@"AllocateStatus_%@",distributionModel.tradeStatus];
    if ([distributionModel.tradeStatus isEqualToString:@"0"]) {
        imageName = @"Distribution_0";
    }else if ([distributionModel.tradeStatus isEqualToString:@"1"]){
        imageName = @"Distribution_1";
    }
    self.imageV.image = [UIImage imageNamed:imageName];
    
    NSString *productViewCostPrice = [NSString stringWithFormat:@"%@",[SAValueManger shareInStance].userInfo.menuList[1][@"perms"][@"productViewCostPrice"]];
    if ([productViewCostPrice isEqualToString:@"1"]) {
        self.priceLab.text = @"￥:******";
    }
}

-(void)initUI {
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.contentLab];
    [self.contentView addSubview:self.numLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.imageV];
    [self.contentView addSubview:self.imageV2];
    
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(64), kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(26, 12, 174, 20)];
        _titleLab.textColor = kBlackColor;
        _titleLab.text = @"申请店：Alina小店";
        _titleLab.font = kFont(15);
    }
    return _titleLab;
}

-(UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:SARectMake(26, 32, 174, 20)];
        _contentLab.textColor = kBlackColor;
        _contentLab.font = kFont(15);
        _contentLab.text = @"调出店：Alina小店";
    }
    return _contentLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(201, 0, 55, 64)];
        _numLab.textColor = kBlackColor;
        _numLab.font = kFont(15);
        _numLab.text = @"8";
        _numLab.textAlignment = NSTextAlignmentCenter;
        _numLab.adjustsFontSizeToFitWidth = YES;
        _numLab.minimumScaleFactor = 0.8;
    }
    return _numLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:SARectMake(256, 0, 80, 64)];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(15);
        _priceLab.text = @"￥:1212";
        _priceLab.textAlignment = NSTextAlignmentLeft;
        _priceLab.adjustsFontSizeToFitWidth = YES;
        _priceLab.minimumScaleFactor = 0.8;
    }
    return _priceLab;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:SARectMake(kBaseScreenWidth - 74, 0, 74, 32)];
        _imageV.image = [UIImage imageNamed:@"AllocateStatus_0"];
        _imageV.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageV;
}

-(UIImageView *)imageV2 {
    if (!_imageV2) {
        _imageV2 = [[UIImageView alloc] initWithFrame:SARectMake(336, 22, 20, 20)];
        _imageV2.image = [UIImage imageNamed:@"Allocate_arrow"];
        _imageV2.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageV2;
}

@end
